package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.*;
import com.ruoyi.logistic.domain.vo.NetworkClientGoAreaIncomeVo;
import com.ruoyi.logistic.domain.vo.NetworkOutboundGoAreaIncomeVo;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeGoAreaIncomeVo;
import com.ruoyi.logistic.service.NetworkAreaIncomeService;
import com.ruoyi.logistic.utils.TableUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/network/areaIncome")
@RestController
@Api(tags = "网点财务_区域收入分析")
public class NetworkAreaIncomeController {
    @Autowired
    private NetworkAreaIncomeService networkAreaIncomeService;
    @Autowired
    private TableService tableService;


    @ApiOperation("出港")
    @PostMapping("/outbound")
    public R outboundGoAreaIncome(@RequestBody NetworkOutboundGoAreaIncomeVo vo) {
        if (vo.getStartTime() == null || vo.getEndTime() == null || vo.getNetworkNameId() == null) {
            return R.fail("请选择所需的时间参数和网点信息");
        }
        if (vo.getProvince() == null) {
            return R.fail("请传入省份信息");
        }
        List<NetworkOutboundGoAreaIncome> list = networkAreaIncomeService.outboundGoAreaIncome(vo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkOutboundGoAreaIncome());
        return TableUtils.handleListResponse(list, fieldList, "暂无数据");
    }

    @ApiOperation("承包区")
    @PostMapping("/undertake")
    public R undertakeGoAreaIncome(@RequestBody NetworkUndertakeGoAreaIncomeVo vo) {
        if (vo.getStartTime() == null || vo.getEndTime() == null || vo.getNetworkNameId() == null) {
            return R.fail("请选择所需的时间参数和网点信息");
        }
        if (vo.getProvince() == null) {
            return R.fail("请传入省份信息");
        }
        List<NetworkUndertakeGoAreaIncome> list = networkAreaIncomeService.undertakeGoAreaIncome(vo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkUndertakeGoAreaIncome());
        return TableUtils.handleListResponse(list, fieldList, "暂无数据");
    }

    @ApiOperation("客户")
    @PostMapping("/client")
    public R clientGoAreaIncome(@RequestBody NetworkClientGoAreaIncomeVo vo) {
        List<NetworkClientGoAreaIncome> list = networkAreaIncomeService.clientGoAreaIncome(vo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkClientGoAreaIncome());
        return TableUtils.handleListResponse(list, fieldList, "暂无数据");
    }
}
